
<template>
  <el-container>
    <el-header>
      <div class="left-panel">
        <!-- <el-button type="primary" icon="el-icon-plus" @click="add"></el-button>
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          :disabled="selection.length == 0"
          @click="batchDel"
        ></el-button> -->
      </div>
      <div class="right-panel">
        <div class="right-panel-search">
          <el-select
            v-model="search.checkStatus"
            style="width: 170px"
            placeholder="请选择审核状态"
            clearable
          >
            <el-option
              v-for="item in statusItems"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
          <el-select
            v-model="search.refuse"
            style="width: 170px"
            placeholder="请选择接收状态"
            clearable
          >
            <el-option
              v-for="item in statusItems2"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
          <el-button
            type="primary"
            icon="el-icon-search"
            @click="upSearch"
          ></el-button>
        </div>
      </div>
    </el-header>
    <el-main class="nopadding">
      <scTable
        ref="table"
        :apiObj="apiObj"
        @selection-change="selectionChange"
        stripe
      >
        <el-table-column type="selection" width="50"></el-table-column>
        <!-- <el-table-column
            label="编号"
            prop="id"
            width="80"
            sortable
        ></el-table-column> -->
        <el-table-column
          label="文稿标题"
          prop="articleTitle"
          width="150"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          label="分配专家"
          prop="expertUserName"
          width="150"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column label="审核状态" prop="checkStatus" width="120">
          <template #default="scope">
            <el-tag
              v-if="scope.row.checkStatus == 0"
              type="info"
              disable-transitions
              >未审核</el-tag
            >
            <el-tag
              v-if="scope.row.checkStatus == 1"
              type="success"
              disable-transitions
              >审核通过</el-tag
            >
            <el-tag
              v-if="scope.row.checkStatus == 2"
              type="danger"
              disable-transitions
              >未通过</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column label="接收状态" prop="refuse" width="120">
          <template #default="scope">
            <el-tag v-if="scope.row.refuse == 0" type="info" disable-transitions
              >等待</el-tag
            >
            <el-tag
              v-if="scope.row.refuse == 1"
              type="success"
              disable-transitions
              >已接收</el-tag
            >
            <el-tag
              v-if="scope.row.refuse == 2"
              type="danger"
              disable-transitions
              >已拒绝</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" align="right" width="170">
          <template #default="scope">
            <el-button-group v-if="scope.row.refuse != 1">
              <el-button type="primary" size="small" @click="user(scope.row)"
                >重新分配</el-button
              >
            </el-button-group>
            <el-button-group v-if="scope.row.checkStatus == 2">
              <el-button type="info" size="small" @click="openReject(scope.row)"
                >驳回原因</el-button
              >
            </el-button-group>
            <el-button size="small" @click="tableShow(scope.row, scope.$index)"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </scTable>
    </el-main>
  </el-container>
  <save-dialog
    v-if="dialog.save"
    ref="saveDialog"
    @success="handleSuccess"
    @closed="dialog.save = false"
  >
  </save-dialog>
  <el-drawer
    v-model="dialog.user"
    :size="760"
    :title="userTitle"
    direction="rtl"
    destroy-on-close
  >
    <user-dialog
      ref="userDialog"
      @success="handleSuccess"
      @closeDrawer="dialog.user = false"
    ></user-dialog>
  </el-drawer>
  <el-dialog
    v-model="dialog.refuse"
    :size="560"
    title="驳回"
    direction="rtl"
    destroy-on-close
  >
    <el-form
      :model="form2"
      label-width="80px"
      label-position="right"
      ref="dialogForm2"
    >
      <el-form-item label="修改建议" prop="callbackAdvise">
        <el-input
          type="textarea"
          rows="5"
          v-model="form.callbackAdvise"
          maxlength="500"
          show-word-limit
          clearable
          disabled
        ></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <div>
        <el-button @click="dialog.refuse = false">取 消</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script>
import userDialog from "./user";
import saveDialog from "./save";
export default {
  name: "articleExpertManger",
  components: {
    userDialog,
    saveDialog,
  },
  data() {
    return {
      dialog: {
        refuse: false,
        save: false,
        user: false,
      },
      form: {
        callbackAdvise: "",
      },
      showGrouploading: false,
      apiObj: this.$API.articleExpert.managerPage,
      selection: [],
      search: {
        keyword: null,
      },
      statusItems: [
        {
          value: 0,
          label: "未审核",
        },
        {
          value: 1,
          label: "审核通过",
        },
        {
          value: 2,
          label: "未通过",
        },
      ],
      statusItems2: [
        {
          value: 0,
          label: "等待",
        },
        {
          value: 1,
          label: "已接收",
        },
        {
          value: 2,
          label: "已拒绝",
        },
      ],
    };
  },
  watch: {},
  mounted() {},
  methods: {
    //搜索
    upSearch() {
      this.$refs.table.upData(this.search);
    },
    user(row) {
      this.dialog.user = true;
      console.log(row);
      this.$TOOL.session.set("TEMP_FIELD_ID", row.fieldId);
      this.$TOOL.session.set("TEMP_ARTICLE_ID", row.articleId);
      this.$TOOL.session.set("TEMP_EXPERT_ID", row.expertUserId);
      this.userTitle = "选择该领域专家";
      this.$nextTick(() => {
        this.$refs.userDialog.open();
      });
    },
    async openReject(row) {
      this.dialog.refuse = true;
      var res = await this.$API.articleExpert.detail.get({ id: row.id });
      if (res.code == "200") {
        this.form = res.data;
      }
    },
    //添加
    add() {
      this.dialog.save = true;
      this.$nextTick(() => {
        this.$refs.saveDialog.open();
      });
    },

    //详情
    tableShow(row) {
      this.dialog.save = true;
      this.$nextTick(() => {
        this.$refs.saveDialog.open("show").setData(row);
      });
    },
    //本地更新数据
    handleSuccess(data, mode) {
      if (mode == "add") {
        this.$refs.table.refresh();
      } else if (mode == "edit") {
        this.$refs.table.refresh();
      }
    },
    //表格选择后回调事件
    selectionChange(selection) {
      this.selection = selection;
    },
    //接收
    async accept(row) {
      var reqData = new FormData();
      reqData.append("id", row.id);
      var res = await this.$API.articleExpert.accept.post(reqData);
      if (res.code == 200) {
        this.$refs.table.refresh();
        this.$message.success("接收成功");
      } else {
        this.$alert(res.message, "提示", { type: "error" });
      }
    },
    //拒绝
    async refuse(row) {
      var reqData = new FormData();
      reqData.append("id", row.id);
      var res = await this.$API.articleExpert.refuse.post(reqData);
      if (res.code == 200) {
        this.$refs.table.refresh();
        this.$message.success("拒绝成功");
      } else {
        this.$alert(res.message, "提示", { type: "error" });
      }
    },
    //批量删除
    async batchDel() {
      this.$confirm(
        `确定删除选中的 ${this.selection.length} 个选项吗？`,
        "提示",
        {
          type: "warning",
          confirmButtonText: "确定",
          confirmButtonClass: "el-button--danger",
        }
      )
        .then(async () => {
          const loading = this.$loading();
          let ids = this.selection.map((item) => {
            return item.id;
          });
          var reqData = new FormData();
          reqData.append("ids", ids);
          var res = await this.$API.articleExpert.batchDelete.post(reqData);
          if (res.code == 200) {
            this.$refs.table.refresh();
            this.$message.success("删除成功");
          } else {
            this.$alert(res.message, "提示", { type: "error" });
          }
          loading.close();
        })
        .catch(() => {});
    },
  },
};
</script>
